/** ==================================================================================== **/
/** 			     Funzioni di utilità per manipolare lo stile delle feature	 		 **/
/** ==================================================================================== **/

BootApplication.service("olStyleService", [ "configuration", function( appConstants ) {
	
	 /**
	  * Ritorna il descrittore dello stile per la feature che geolocalizza la posizione dell'utente.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleFeatureGeolocate = function (){
		 
		 var iconStyle = new ol.style.Style({
				image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
				   /** Anchor. Default value is [0.5, 0.5] (icon center). **/
				   anchor: [0.5, 46],
				   /** 
				    * Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon.
				    * A value of 'pixels' indicates the x value in pixels. Default is 'fraction'. **/
				   anchorXUnits: 'fraction',
				   /**
				    * Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. 
				    * A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.
				    */
			       anchorYUnits: 'pixels',
				   opacity: 1,
				   src: appConstants.getParam("Constants").ContextPath + "images/marker/m_geolocation.png", // TODO DECIDERE QUALE USARE
				   /** Icon size in pixel. **/
//				   size: [24, 24],
				   rotateWithView: true
				}))
			});
		 
		 return iconStyle;
	 }// close createStyleFeatureGeolocate
	 
	 /**
	  * Ritorna il descrittore dello stile della feature che si sta disegnando quando l'interazione MeasureLength è attiva.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createSketchStyleFeatureMeasureLength = function (){
		 
		 var style =
			 new ol.style.Style({
		    	fill: new ol.style.Fill({
			        color: 'rgba(255, 255, 255, 0.2)'
			    }),
			    stroke: new ol.style.Stroke({
			        color: 'rgba(0, 0, 0, 0.5)',
			        lineDash: [10, 10],
			        width: 2
			    }),
			    image: new ol.style.Circle({
			    	radius: 5,
			    	stroke: new ol.style.Stroke({
			           color: 'rgba(0, 0, 0, 0.7)'
			        }),
			        fill: new ol.style.Fill({
			           color: 'rgba(255, 255, 255, 0.2)'
			        })
			    })
		    });
		 
		 return style;
	 }// close createStyleFeatureMeasureLength
	 
	 /**
	  * Ritorna il descrittore dello stile della feature che si sta disegnando quando l'interazione MeasureArea è attiva.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createSketchStyleFeatureMeasureArea = function (){
		 
		 var style =
			 new ol.style.Style({
			    fill: new ol.style.Fill({
			    	color: 'rgba(255, 255, 255, 0.2)'
				}),
				stroke: new ol.style.Stroke({
					color: 'rgba(0, 0, 0, 0.5)',
					lineDash: [10, 10],
					width: 2
				}),
				image: new ol.style.Circle({
					radius: 5,
					stroke: new ol.style.Stroke({
						color: 'rgba(0, 0, 0, 0.7)'
				    }),
				    fill: new ol.style.Fill({
				    	color: 'rgba(255, 255, 255, 0.2)'
				    })
				})
			});
		 
		 return style;
	 }// close createStyleFeatureMeasureArea
	 
	 /**
	  * Ritorna il descrittore dello stile della feature che si sta disegnando quando l'interazione MeasureAzimut è attiva.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createSketchStyleFeatureMeasureAzimut = function (){
		 
		 var style =
			 new ol.style.Style({
			    fill: new ol.style.Fill({
			    	color: 'rgba(255, 255, 255, 0.2)'
				}),
				stroke: new ol.style.Stroke({
					color: 'rgba(0, 0, 0, 0.5)',
					lineDash: [10, 10],
					width: 2
				}),
				image: new ol.style.Circle({
					radius: 5,
					stroke: new ol.style.Stroke({
						color: 'rgba(0, 0, 0, 0.7)'
				    }),
				    fill: new ol.style.Fill({
				    	color: 'rgba(255, 255, 255, 0.2)'
				    })
				})
			});
		 
		 return style;
	 }// close createStyleFeatureMeasureAzimut
	 
	 /**
	  * Ritorna il descrittore dello stile per la feature prodotta dagli strumenti di disegno.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleFeatureDraw = function (){
		 
		 var simple = 
			   new ol.style.Style({
				   fill: new ol.style.Fill({
					   color: 'rgba(255, 255, 255, 0.5)'
				   }),
				   stroke: new ol.style.Stroke({
					    color: '#A94442',
				        lineDash: [10, 10],
				        width: 3
				   }),
				   image: new ol.style.Circle({
					   radius: 7,
					   fill: new ol.style.Fill({
						   color: '#A94442'
					   })
				   })
			  });
		 
		 return simple;
	 }// close createStyleFeatureDraw
	 
	 /**
	  * Ritorna il descrittore dello stile della feature che si sta disegnando quando l'interazione Draw è attiva.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createSketchStyleFeatureDraw = function (){
		 
		 var style =
			 new ol.style.Style({
			    fill: new ol.style.Fill({
			    	color: 'rgba(255, 255, 255, 0.2)'
				}),
				stroke: new ol.style.Stroke({
					color: 'rgba(0, 0, 0, 0.5)',
					lineDash: [10, 10],
					width: 2
				}),
				image: new ol.style.Circle({
					radius: 5,
					stroke: new ol.style.Stroke({
						color: 'rgba(0, 0, 0, 0.7)'
				    }),
				    fill: new ol.style.Fill({
				    	color: 'rgba(255, 255, 255, 0.2)'
				    })
				})
			});
		 
		 return style;
	 }// close createSketchStyleFeatureDraw
	 
	 /**
	  * Ritorna il descrittore dello stile del marker usato per individuare su mappa un punto localizzato con lo strumento di "Cerca Lon/Lat".
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleGeoLonLat = function () {
		 
		 var style = new ol.style.Style({
		 	image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
		 	   /** Anchor. Default value is [0.5, 0.5] (icon center). **/
		 	   anchor: [0.5, 0.5],
		 	   /** 
		 	    * Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon.
		 	    * A value of 'pixels' indicates the x value in pixels. Default is 'fraction'. **/
		 	   anchorXUnits: 'fraction',
		 	   /**
		 	    * Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. 
		 	    * A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.
		 	    */
		       anchorYUnits: 'fraction',
		 	   opacity: 1,
		 	   src: appConstants.getParam("Constants").ContextPath + "images/marker/m_cercalonlat.png",
		 	   /** Icon size in pixel. **/
//		 	   size: [24, 24],
		 	   rotateWithView: true
		 	}))
		 });
		 
		return style;
	 }// close createStyleGeoLonLat
	 
	 /**
	  * Ritorna un descrittore dello stile di default.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleDefault = function () {
		 
		 var style = new ol.style.Style({
				image: new ol.style.Circle({
			        /** Circle radius. **/
				    radius: 7,
				    /** **/
				    snapToPixel: false,
				    /** Fill style. **/
				    fill: new ol.style.Fill({ color: 'blue' }),
				    /** Stroke style.**/
				    stroke: new ol.style.Stroke({ color: 'white', width: 2 })
				})
			});
		 
		return style;
	 }// close createStyleDefault
	 
	 /**
	  * Ritorna il descrittore dello stile del marker usato per individuare su mappa il punto localizzato dal geocoder.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleGeoIndirizzo = function () {
		 
		 var style = new ol.style.Style({
		 	image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
		 	   /** Anchor. Default value is [0.5, 0.5] (icon center). **/
		 	   anchor: [0.5, 0.5],
		 	   /** 
		 	    * Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon.
		 	    * A value of 'pixels' indicates the x value in pixels. Default is 'fraction'. **/
		 	   anchorXUnits: 'fraction',
		 	   /**
		 	    * Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. 
		 	    * A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.
		 	    */
		       anchorYUnits: 'fraction',
		       /** **/
		       opacity: 1,
		 	   /** **/
		 	   src: appConstants.getParam("Constants").ContextPath + "images/marker/m_geocoder.png",
		 	   /** Icon size in pixel. **/
//		 	   size: [24, 24],
		 	   /** **/
		 	   rotateWithView: true
		 	}))
		 });
		 
		return style;
	 }// close createStyleGeoIndirizzo
	 
	 /**
	  * Ritorna il descrittore dello stile del marker usato per individuare su mappa il punto localizzato dal geocoder.
	  * 
	  * Returns:  
	  * 	  {@link ol.style.Style} Style.
	  */
	 this.createStyleGeoFermata = function () {
		 
		 var style = new ol.style.Style({
		 	image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
		 	   /** Anchor. Default value is [0.5, 0.5] (icon center). **/
		 	   anchor: [0.5, 0.5],
		 	   /** 
		 	    * Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon.
		 	    * A value of 'pixels' indicates the x value in pixels. Default is 'fraction'. **/
		 	   anchorXUnits: 'fraction',
		 	   /**
		 	    * Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. 
		 	    * A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.
		 	    */
		       anchorYUnits: 'fraction',
		       /** **/
		       opacity: 1,
		 	   /** **/
		 	   src: appConstants.getParam("Constants").ContextPath + "images/marker/m_geocoder.png",
		 	   /** Icon size in pixel. **/
//		 	   size: [24, 24],
		 	   /** **/
		 	   rotateWithView: true
		 	}))
		 });
		 
		return style;
	 }// close createStyleGeoIndirizzo
	 
	 /**
	  * Ritorna un descrittore dello stile dove il marker è un icona.
	  * 
	  * @param {@link String} srcIco, path dell'icona che fa da marker
	  * @param {@link Array.<number>} size, An array of numbers representing a size: [width, height]. Default è [24, 24]
	  * @param {@link Array.<number>} anchor, Anchor. Default value is [0.5, 0.5] (icon center).
	  * Returns:  
	  * 	  {@link ol.style.Icon} Style.
	  */
	 this.createOlStyleIcon = function (srcIco, size, anchor) {
		 
		 var style = new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
		 	   /** Anchor. Default value is [0.5, 0.5] (icon center). **/
		 	   anchor: (anchor != null && angular.isArray(anchor)) ? anchor : [0.5, 0.5],
		 	   /** 
		 	    * Units in which the anchor x value is specified. A value of 'fraction' indicates the x value is a fraction of the icon.
		 	    * A value of 'pixels' indicates the x value in pixels. Default is 'fraction'. **/
		 	   anchorXUnits: 'fraction',
		 	   /**
		 	    * Units in which the anchor y value is specified. A value of 'fraction' indicates the y value is a fraction of the icon. 
		 	    * A value of 'pixels' indicates the y value in pixels. Default is 'fraction'.
		 	    */
		       anchorYUnits: 'fraction',
		       /** */
		 	   opacity: 1,
		 	   /** */
		 	   src: srcIco,
		 	   /** Icon size in pixel. **/
		 	   size: size != null ? size : [24, 24],
		 	   /** */
		 	   rotateWithView: true
		  }));
		 
		return style;
	}// close createOlStyleIcon
	 
	/**
	 * Crea stile semplice (senza immagine) per punto
	 */	 
	this.createSimpleStylePoint = function(){
		 return new ol.style.Style({
			 			image: new ol.style.Circle({
			 				radius: 2, 
			 				fill: new ol.style.Fill ({color: 'red'}), 
			 				stroke: new ol.style.Stroke({color: 'red', width: 1})
			 			})
	            });
	}//close createSimpleStylePoint
	
	/**
	 * Style di default per circonferenza
	 */	
	this.createCirconferenzaStyle = function(){
		return new ol.style.Style({ stroke: new ol.style.Stroke({color: 'blue', width: 3 }) });
	}//end createCirconferenzaStyle
	
	/**
	 * Style di default per i polygon
	 */	
	this.createDefaultPolygonStyle = function(){
    	return new ol.style.Style({
    					stroke: new ol.style.Stroke({color: '#00FF00', width: 3}), zIndex: 2
    	           });
    }//end createDefaultPolygonStyle
}]); 
